function matrix_stats_plot3(stats_file, id_1, title_1, id_2, title_2, id_3, title_3)
% Renders one figure with three movie histograms for a matrix.stats 
% file (see Makefile).
% stats_file is taken relative to the parent of the src folder.

styles = {'k', 'k--', 'k-.'};
ext = 'eps';
ids_string = [num2str(id_1) '_' num2str(id_2) '_' num2str(id_3)];
out_file = [stats_file '_' ids_string '.' ext]

figure
clf
hold on

in_fid = fopen(['../' stats_file], 'r');
row = 0;
id_number = 0;
while 1
  row = row + 1;

  % Read line.
  line = fgetl(in_fid);
  if ~ischar(line)
    break
  end

  % Assume input in order by movie ID.
  if row == id_1 || row == id_2 || row == id_3
    id_number = id_number + 1;

    % The bins are the last thing on the line, following 'bins='.
    % Keep the start of the line (remain) for later.
    [bin_string, remain] = strtok(fliplr(line), '=');
    bins = str2num(fliplr(bin_string));

    bin_count = length(bins);
    if mod(bin_count, 2) == 1
      error 'odd number of bins'
    end

    % Each row of hist is a value, count pair.
    hist = reshape(bins,2,bin_count/2)';

    % Plot to image file.
    % Unfortunately, Matlab dies randomly here.
    plot(hist(:,1),hist(:,2),styles{id_number}, 'LineWidth', 2)
  end
end
fclose(in_fid);

title('cosine similarity distributions for 3 movies');
set(gcf, 'PaperPositionMode', 'auto', ...
         'Resize', 'off', ...
         'Position', [0 0 600 400]);
legend(strrep(title_1,'_',' '),strrep(title_2,'_',' '),strrep(title_3,'_',' '));
%print('-dpng', ['../' out_file]);
print('-deps', ['../' out_file]);

